package cn.bluech.lib.utils;

import android.content.Context;
import android.media.AudioManager;

import androidx.annotation.NonNull;

/**
 * 音频焦点请求/释放工具类
 */
public class AudioUtils {
    public static void requestAudioFocus(@NonNull Context context){
        requestAudioFocus(context,AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN);
    }

    public static void requestAudioFocus(@NonNull Context context,int streamType, int durationHint){
        AudioManager am = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
        if(null!=am)
            am.requestAudioFocus(null, streamType, durationHint);
    }

    public static void abandonAudioFocus(@NonNull Context context){
        AudioManager am = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
        if(null!=am)
            am.abandonAudioFocus(null);
    }
}
